#!/bin/sh
# Checking Dialing/DWDS morphology
# written by Alexey Sokirko 2003, sokirko@yandex.ru

halt() {
	echo  "======================"
	echo  "Error: $errorstr"
	echo
	exit  1
}

bad_arguments() {
	errorstr="the first argument should be Russian, English or German"
	halt;
}



if [ $# != 1 ]; then
	bad_arguments;
fi


for i in Russian English German; do
	if [ $i = $1 ]; then
		Language=`expr substr $i 1 3`
		break;
	fi
done


./gen_graphan_bin.sh  $1
if [ "$?" -ne "0" ]; then
	halt;
fi

if [ $1 = "Russian" ]; then
	./compile_ross.sh Dicts/Ross
	if [ "$?" -ne "0" ]; then
		halt;
	fi
	Bin/ConvertTrigramBinary  Dicts/Trigram/full.rev.config
	if [ "$?" -ne "0" ]; then
		halt;
	fi
	

fi

if [ $1 = "German" ]; then

	Bin/SimpleGrammarPrecompiled German Dicts/SimpleGrammar/example.grm
	if [ "$?" -ne "0" ]; then
		halt;
	fi


	Bin/SimpleGrammarPrecompiled German Dicts/GerSynan/gformats.txt
	if [ "$?" -ne "0" ]; then
		halt;
	fi

fi


echo "======== Checking Synan with the simple test ($1) ========"
Bin/TestSynan $1 Test/Synan/$Language/test.txt  >test.temp

cmp test.temp Test/Synan/$Language/result.txt

if [ "$?" -ne "0" ]; then
	#rm test.temp
	errorstr="Synan doesn't work! The simple test failed!"
	halt;
fi

rm test.temp

echo
echo  "Everything is OK!"
